<style scoped>

</style>
<template>
    <DatePicker v-model="timeProxy" :type='type' v-bind='$attrs'>
    </DatePicker>
</template>

<script>

function typeCheck(type){
    return ['daterange','datetimerange'].includes(type) 
}

export default {
    
    props:{
        type: {
            default: 'date'
        },
        value: {
            default: ''
        },
        startTime: {
            default: ''
        },
        endTime:{
            default: ''
        }
    },
    computed:{
        timeProxy:{
            get(){
                const { value, startTime, endTime, type } = this
                if(typeCheck(type)){return [ startTime, endTime ] }
                return value
            },
            set(data){ 
                
                const { type } = this

                if(typeCheck(type)){
                    console.log('change')
                    this.$emit('update:startTime', data[0])
                    this.$emit('update:endTime', data[1])
                    return 
                }
                
                this.$emit('input', data)
            }
        }
    }

}
</script>
